home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / makefmt.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  6KB  |  235 lines

  1. /*    parseFMT.C    */
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <stdio.h>
  7. #include "parseafm.h"
  8. int debugit=0;
  9. #define dbg if (debugit)
  10. int chrcat(char *s,char c);
  11. int str_ascii(char *s) ;
  12. int writefmt(void);
  13. /*-----------------------------------------------------------------------*/
  14. /* Globals */
  15. FontInfo *fi;
  16. FLAGS myflags = P_ALL;
  17.  
  18. /*-----------------------------------------------------------------------*/
  19.  
  20. char fmtname[80];
  21. main( int argc, char **argv)
  22. {
  23.   char *s;
  24.     char filename[80];
  25.     FILE *fp;
  26.  
  27.     myflags = P_ALL;
  28.  
  29.     strcpy(filename,*(++argv));
  30.     s = strchr(filename,'.');
  31.     if (s!=NULL) *s=0;
  32.     strcpy(fmtname,filename);
  33.     if (strchr(filename,':')!=NULL) strcpy(fmtname,strchr(filename,':')+1);
  34.     strcat(fmtname,".fmt");
  35.     strcat(filename,".afm");
  36.     printf("Processing {%s}, creating {%s} \n",filename,fmtname);
  37.  
  38.     if (!filename[0]) {
  39.       printf ("*** ERROR: can't open. filename is missing.\n",filename );
  40.       return 0;
  41.     }
  42.     printf("Reading ADOBE font metric file {%s} \n ",filename);
  43.     fp = fopen(filename, "r" );
  44.     if (fp == NULL) {
  45.         printf ("*** ERROR: can't find: %s\n", filename );
  46.         perror("");
  47.         exit(1);
  48.     }
  49.  
  50.     switch (parseFile(fp, &fi, myflags)) {
  51.     case parseError:
  52.         printf("*** ERROR: problem in parsing the AFM File.\n");
  53.         exit(1);
  54.     case ok:
  55.         fclose(fp);
  56.         writefmt();
  57.         break;
  58.     case earlyEOF:
  59.         printf("The AFM File ended prematurely.\n");
  60.         exit(1);
  61.         break;
  62.     default:
  63.         break;
  64.     }
  65.     printf("Successful completioin \n");
  66.   exit(0);
  67. }
  68.  
  69. /*-----------------------------------------------------------------------*/
  70. struct xypair {float x,y;} ;
  71. struct allchar {char lig[4],lrep[4],kern[35]; struct xypair kxy[35];
  72. } *ap[256];
  73. /* *ap[256];  */
  74. struct char_data { float wx,wy,x1,y1,x2,y2; } cc ;
  75. struct char_datax { char *kern, *lig, *krep, *lrep; };
  76. struct font_table {
  77.     char *name;
  78.     char *full_name;
  79.     char *file_metric;
  80.     char *file_vector;
  81.     char *file_bitmap;
  82.     struct char_data ( *chr)[256];
  83.     int encoding;           /* 1 = postscript text , 2=postscrip symbol, */
  84.                 /* 3=TEX text, 4=TEX symbol, 5=TEX extensions */
  85.     float space,space_stretch,space_shrink;
  86.     float scale,slant,uposition,uthickness;
  87.     float fx1,fy1,fx2,fy2,caphei,xhei,descender,ascender;
  88. } fnt;
  89. FILE *fmt;
  90. int c1,c2,ll,lk,n;
  91.  
  92. writefmt()
  93. {
  94.     int i = 0,zz;
  95.     double fff;
  96.     char *sss;
  97.     int dec,sgn;
  98.     CharMetricInfo *temp = fi->cmi;
  99.     Ligature *node = temp->ligs;
  100.     PairKernData *pkd = fi->pkd;
  101.     float fval,scl;
  102.     fff = 2;
  103.     /* sss is never used    a.r. */
  104.     /* sss = (char *) ecvt(fff,2,&dec,&sgn); */
  105. #ifdef unix
  106.     fmt = fopen(fmtname,"w");
  107. #else
  108.     fmt = fopen(fmtname,"wb");
  109. #endif
  110.     if (fmt == NULL) {
  111.         perror ("Cant open output file ");
  112.         exit(1);
  113.     }
  114.     fnt.encoding = 1;       /* AdobeStandardEncoding */
  115.     printf("The font name is %s\n", fi->gfi->fontName);
  116.     if (0==strcmp(fi->gfi->encodingScheme,"TEXENCODING")) {
  117.         fnt.encoding = 3;       /* AdobeStandardEncoding */
  118.     }
  119.     if (0==strcmp(fi->gfi->encodingScheme,"AdobeStandardEncoding")) {
  120.         fnt.encoding = 1;       /* AdobeStandardEncoding */
  121.     }
  122.     if (0==strcmp(fi->gfi->encodingScheme,"GLEMARK")) {
  123.         fnt.encoding = 5;
  124.     }
  125.     printf("Encoding scheme {%s} %d \n"
  126.         ,fi->gfi->encodingScheme,fnt.encoding);
  127.     fnt.scale = 1000;
  128.     scl = .001;
  129.     fnt.slant = fi->gfi->italicAngle;
  130.     fnt.uposition = fi->gfi->underlinePosition*scl;
  131.     fnt.uthickness =  fi->gfi->underlineThickness*scl;
  132.     fnt.fx1 = fi->gfi->fontBBox.llx*scl;
  133.     fnt.fy1 = fi->gfi->fontBBox.lly*scl;
  134.     fnt.fx2 = fi->gfi->fontBBox.urx*scl;
  135.     fnt.fy2 = fi->gfi->fontBBox.ury*scl;
  136.     fnt.caphei = fi->gfi->capHeight*scl;
  137.     fnt.xhei = fi->gfi->xHeight*scl;
  138.     fnt.descender = fi->gfi->descender*scl;
  139.     fnt.ascender = fi->gfi->ascender*scl;
  140.  
  141.     temp = fi->cmi;
  142.     zz = 1;
  143.     for (temp=fi->cmi;zz < fi->numOfChars; temp++) {
  144.         zz++;
  145.         if (temp->code==32) {
  146.             fnt.space = temp->wx*scl;
  147.             fnt.space_stretch = fnt.space*.5;
  148.             fnt.space_shrink = fnt.space*.3;
  149.             break;
  150.         }
  151.     }
  152.  
  153.     temp = fi->cmi;
  154.     fwrite(&fnt.encoding,4,16,fmt);
  155.  
  156.     zz = 0;
  157.     for (i = 0; i < 256 ; ++i) {
  158.       if (i<temp->code || zz >= fi->numOfChars ) {
  159.         cc.wx = 0;
  160.         cc.wy = 0;
  161.         cc.x1 = 0;
  162.         cc.x2 = 0;
  163.         cc.y1 = 0;
  164.         cc.y2 = 0;
  165.       } else {
  166.         cc.wx = temp->wx*scl;
  167.         cc.wy = temp->wy*scl;
  168.         cc.x1 = temp->charBBox.llx*scl;
  169.         cc.x2 = temp->charBBox.urx*scl;
  170.         cc.y1 = temp->charBBox.lly*scl;
  171.         cc.y2 = temp->charBBox.ury*scl;
  172.           for (node=temp->ligs;node !=NULL; node = node -> next) {
  173.         if (ap[i]==NULL) ap[i] = calloc(1,sizeof(*ap[i]));
  174.         if (ap[i]==NULL) printf("memory allocation error \n");
  175.             chrcat(ap[i]->lig,str_ascii(node->succ));
  176.             chrcat(ap[i]->lrep,str_ascii(node->lig));
  177.           }
  178.         zz++;
  179.         temp++;
  180.       }
  181.       fwrite(&cc,sizeof(cc),1,fmt);
  182.     } /* for */
  183.     dbg printf("got char %d %d\n",i,zz);
  184.  
  185.     dbg printf("Here comes the pair kerning data ...\n");
  186.     if (fi->numOfPairs != 0) {
  187.       for (i = 0; i < fi->numOfPairs; ++i) {
  188.         c1 = str_ascii(pkd[i].name1);
  189.         c2 = str_ascii(pkd[i].name2);
  190.         if (ap[c1]==NULL) ap[c1] = calloc(1,sizeof(*ap[c1]));
  191.         if (ap[c1]==NULL) printf("memory allocation error \n");
  192.         chrcat(ap[c1]->kern,c2);
  193.         n = strlen(ap[c1]->kern)-1;
  194.         ap[c1]->kxy[n].x = pkd[i].xamt*scl;
  195.         ap[c1]->kxy[n].y = pkd[i].yamt*scl;
  196.       }
  197.     }
  198.  
  199.     for (i=1;i<256;i++) {
  200.         if (ap[i]==NULL) continue;
  201.         ll = strlen(ap[i]->lig);
  202.         lk = strlen(ap[i]->kern);
  203.         if (ll>0 || lk>0) {
  204.             fputc(i,fmt);
  205.             fputc(ll,fmt);
  206.             fwrite(ap[i]->lig,1,ll,fmt);
  207.             fwrite(ap[i]->lrep,1,ll,fmt);
  208.             fputc(lk,fmt);
  209.             fwrite(ap[i]->kern,1,lk,fmt);
  210.             fwrite(ap[i]->kxy,8,lk,fmt);
  211.         }
  212.     }
  213.     fputc(0,fmt);
  214.     fclose(fmt);
  215. }
  216. chrcat(char *s,char c)
  217. {
  218.     int i;
  219.     i = strlen(s);
  220.     *(s+i) = c;
  221. }
  222. int str_ascii(char *s)
  223. {
  224.     int i;
  225.     CharMetricInfo *temp = fi->cmi;
  226.  
  227.     for (i=0;i<fi->numOfChars; ++i) {
  228.         if (strcmp(temp->name,s)==0) {
  229.             return temp->code;
  230.         }
  231.         temp++;
  232.     }
  233.     printf("Failed to find char, fatal error ********* {%s} \n",s);
  234. }
  235.